package com.factorit.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts.actions.DispatchAction;

import com.factorit.mvc.MvcSession;
import com.factorit.mvc.SessionImpl;
import com.factorit.security.SessionPrincipal;

public class BaseDispatchableAction extends DispatchAction {
	public void populateRequest(HttpServletRequest request) {
		SessionPrincipal sessionPrincipal = getUserPrincipal(request);
		request.setAttribute("userIdSession", sessionPrincipal.getUser().getId());
	}

	public MvcSession getMvcSession(HttpSession httpSession) {
		return new SessionImpl(httpSession);
	}

	public SessionPrincipal getUserPrincipal(HttpServletRequest request) {
		return (SessionPrincipal) request.getUserPrincipal();
	}
}
